
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/**
 * splash view
 */
class SplashView extends StatefulWidget {
  final String mMediaId;
  final double? width;
  final double? height;
  final int? timeOut;
  SplashView({super.key,required this.mMediaId,this.width,this.height,this.timeOut});

  @override
  State<SplashView> createState() => _SplashViewState();
}

class _SplashViewState extends State<SplashView> with AutomaticKeepAliveClientMixin{
  @override
  bool get wantKeepAlive => true;
  //id
  final String viewType = 'com.xt.fcsj.more_ads.event.splash';
  // 参数集合
  late Map<String, dynamic> params;
  // 通信通道
  late MethodChannel _channel;

  @override
  void initState() {
    params = {
      'mMediaId': widget.mMediaId,
      'width': widget.width,
      'height': widget.height,
      'timeOut': widget.timeOut??3500,
    };
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if((widget.mMediaId??'').isEmpty)return SizedBox(width: 0,);
    return  AndroidView(
      viewType: viewType,
      creationParams: params,
      creationParamsCodec: const StandardMessageCodec(),
      onPlatformViewCreated: (id) {
        _channel = MethodChannel('$viewType/$id');
        _channel.setMethodCallHandler((call) => onMethodCall(call));
      },
    );
  }
  //回调
  onMethodCall(MethodCall call)  {
    String method = call.method;
    dynamic arguments = call.arguments;
    print('method-->$method');
    print('arguments-->$arguments');
  }
}
